#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/12/27 20:21
# @Author  : Sun
# @File    : modify_family_note.py
# @Software: PyCharm
import json

import requests

from common.read_yaml import ReadYaml
from common.write_log import WriteLog


# 移除家族成员
from interface.join_party import JoinParty
from interface.modify_sns_prop import ModifySnsProp


class DelSnsMeb:
    _URL = ReadYaml().read_yaml().get('domain') + \
        "/relation/sns/delSnsMeb"
    _DATAOWNER = {
        "dwPidOut": None,
        "removedMemberJJUidArr": []
    }
    _DATASUCCESS = {
        "dwPidOut": None,
        "removedMemberJJUidArr": []
    }
    _HEADERS = {
        'platform': 'RN',
        'authorization': None,
        'Content-Type': 'application/json;charset=utf-8'
    }

    def del_sns_meb_self(self, JJUid, dwPidOut):
        self._DATAOWNER['dwPidOut'] = dwPidOut
        self._DATAOWNER['removedMemberJJUidArr'].append(JJUid)
        self._HEADERS['authorization'] = ReadYaml().read_yaml(file_path="./config/family_token.yaml").get(JJUid)
        r = requests.request(
            method='POST',
            url=self._URL,
            data=json.dumps(
                self._DATAOWNER),
            headers=self._HEADERS)
        result = json.dumps(r.json(), ensure_ascii=False, indent=4)
        WriteLog().write_log().info(result)
        return result

    def del_sns_meb_success(self, JJUid, dwPidOut, member_uid=None):
        self._DATASUCCESS['dwPidOut'] = dwPidOut
        # 设置家族加入条件为自动加入
        modify_result = ModifySnsProp().modify_sns_prop(JJUid=JJUid, dwPidOut=dwPidOut)
        if modify_result:
            # 把一个用户加入家族
            JoinParty().join_party(JJUid=member_uid, partyId=dwPidOut)
        WriteLog().write_log().info(member_uid)
        self._DATASUCCESS['removedMemberJJUidArr'].append(member_uid)
        self._HEADERS['authorization'] = ReadYaml().read_yaml(file_path="./config/family_token.yaml").get(JJUid)
        r = requests.request(
            method='POST',
            url=self._URL,
            data=json.dumps(
                self._DATASUCCESS),
            headers=self._HEADERS)
        result = json.dumps(r.json(), ensure_ascii=False, indent=4)
        WriteLog().write_log().info(result)
        return result


if __name__ == '__main__':
    # ModifyFamilyNote().modify_family_note(JJUid=106146203, dwPidOut=20000686)
    # 管理员 106146624
    DelSnsMeb().del_sns_meb_success(JJUid=106146624, dwPidOut=20000686)
